package com.hg.concurent.demo5;

import cn.hutool.core.thread.ThreadUtil;

import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CyclicBarrier;
import java.util.concurrent.TimeUnit;

/**
 * created by skh on 2019/12/21
 */
public class CyclicBarrierDemo {

	public static void main(String[] args) throws InterruptedException {
		CyclicBarrier cyclicBarrier = new CyclicBarrier(10, () -> {
			System.out.println("召唤神龙");
		});
		for (int i = 0; i < 10; i++) {
			new Thread(()->{
				try {
					System.out.println(Thread.currentThread().getName()+"收集到龙珠");
					cyclicBarrier.await(); //等待其他线程执行完自己的操作
				} catch (Exception e) {
					e.printStackTrace();
				}
			}, Thread.currentThread().getName()+":"+i).start();
		}
	}
}
